import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-03-30
 * Time: 17:00
 */
class DeepPerson implements Cloneable {
    String name;
    String[] hobbies;  // 引用类型字段
    Address address;  // 嵌套引用类型

    public DeepPerson(String name, String[] hobbies, Address address) {
        this.name = name;
        this.hobbies = hobbies;
        this.address = address;
    }

    //实现深拷贝
    @Override
    protected Object clone() throws CloneNotSupportedException {
        DeepPerson cloned = (DeepPerson) super.clone();
        cloned.hobbies = Arrays.copyOf(this.hobbies, this.hobbies.length);  // 复制数组
        cloned.address = (Address) this.address.clone();  // 复制嵌套对象
        return cloned;
    }

    @Override
    public String toString() {
        return name + "- 爱好：" +  String.join(",", hobbies) + "" + "-" + "地址：" + address;
    }
}
